package cn.wetcland.urban.admin.service.impl;

import cn.wetcland.urban.admin.dto.CarUpdateDTO;
import cn.wetcland.urban.admin.mapper.UtCarMapper;
import cn.wetcland.urban.admin.service.UtCarService;
import cn.wetcland.urban.common.MyAssert;
import cn.wetcland.urban.common.utils.CopyObjectUtil;
import cn.wetcland.urban.generator.domain.UtCar;
import cn.wetcland.urban.generator.dto.BaseConditionSearchDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
* @author Wetcland
* @description 针对表【ut_car】的数据库操作Service实现
* @createDate 2024-01-21 09:51:59
*/
@Service
public class UtCarServiceImpl extends ServiceImpl<UtCarMapper, UtCar> implements UtCarService {

    @Resource
    private UtCarMapper carMapper;

    @Override
    public Page<UtCar> verifyCarList(BaseConditionSearchDTO searchDTO) {
        Page<UtCar> utCarPage = new Page<>(searchDTO.getCurPage(), searchDTO.getPageSize());
        return carMapper.selectVerifyCarList(utCarPage, searchDTO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void verifyCar(Long carId) {
        UtCar car = carMapper.selectById(carId);
        MyAssert.notNull(car, "该车辆不存在");
        car.setIsVerifyPass(1);
        carMapper.updateById(car);
    }

    @Override
    public Page<UtCar> carList(BaseConditionSearchDTO searchDTO) {
        Page<UtCar> utCarPage = new Page<>(searchDTO.getCurPage(), searchDTO.getPageSize());
        return carMapper.selectCarPageList(utCarPage, searchDTO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void carUpdate(CarUpdateDTO updateDTO) {
        UtCar car = carMapper.selectById(updateDTO.getCarId());
        MyAssert.notNull(car, "车辆不存在");
        CopyObjectUtil.copyPropertiesIgnoreNull(updateDTO, car);
        carMapper.updateById(car);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void carDelete(Long carId) {
        carMapper.deleteById(carId);
    }
}




